//
//  MJ_OperationViewModel.m
//  UEAssistant
//
//  Created by mac on 2018/1/4.
//  Copyright © 2018年 youyixinxi. All rights reserved.
//

#import "MJ_OperationViewModel.h"
#import "MJProjectBaseModel.h"
#import "MJ_TaskCellLayout.h"
#import "MJProjectListModel.h"
#import "MJReportBaseModel.h"
#import "MJReportListModel.h"

@interface MJ_OperationViewModel ()

@property (strong, nonatomic)MJProjectBaseModel *projectBaseModel;

@property (strong, nonatomic)MJReportBaseModel *reportBaseModel;

@end

@implementation MJ_OperationViewModel

- (MJProjectBaseModel *)projectBaseModel {
    if (!_projectBaseModel) {
        _projectBaseModel = [[MJProjectBaseModel alloc] init];
    }
    return _projectBaseModel;
}

- (MJReportBaseModel *)reportBaseModel {
    if (!_reportBaseModel) {
        _reportBaseModel = [[MJReportBaseModel alloc] init];
    }
    return _reportBaseModel;
}

- (NSMutableArray *)projectList {
    if (!_projectList) {
        _projectList = [NSMutableArray array];
        
    }
    return _projectList;
}
- (NSMutableArray *)reportList {
    if (!_reportList) {
        _reportList = [NSMutableArray array];
    }
    return _reportList;
}
- (NSMutableArray *)searchProjectList {
    if (!_searchProjectList) {
        _searchProjectList = [NSMutableArray array];
    }
    return _searchProjectList;
}

- (NSMutableArray *)managerList {
    if (!_managerList) {
        _managerList = [NSMutableArray array];
    }
    return _managerList;
}

- (void)loadProductReportListWithParameter:(NSDictionary *)parameter success:(OperationResultBlock)success {
    
    [AvailableNetWorking postWithUrl:TeamProductReport_connector params:parameter successHandler:^(id responseObject) {
        [self.reportList removeAllObjects];
        self.reportBaseModel = [MJReportBaseModel mj_objectWithKeyValues:responseObject];
        [self.reportList addObjectsFromArray:self.reportBaseModel.result];
        success(YES);
    } falureHandler:^(NSError *error) {
        success(NO);
        
    }];
}

- (void)loadProjectManagerWithParameter:(NSDictionary *)parameter success:(OperationResultBlock)success {
    [AvailableNetWorking postWithUrl:projectManager_connector params:parameter successHandler:^(id responseObject) {
        TGLog(@"项目监管列表----%@",responseObject);
        self.projectBaseModel = [MJProjectBaseModel mj_objectWithKeyValues:responseObject];
        for (MJProjectListModel *model in self.projectBaseModel.result) {
            MJ_TaskCellLayout *layout = [[MJ_TaskCellLayout alloc] initWithModel:model];
            [self.projectList addObject:layout];
//            NSDictionary *dc = @{@"vmId":[NSString stringWithFormat:@"%ld",model.vm_id],@"vm_name":model.vm_name};
        }
        success(YES);
    } falureHandler:^(NSError *error) {
        success(NO);
    }];
}

//搜索项目监管(语言分类)
- (void)loadProjectWithSourceKey:(NSString *)sourceKey targetKey:(NSString *)targetKey success:(OperationResultBlock)success{
    NSDictionary *parameter = @{@"pagenum":@"1",
                                @"pagesize":@"500",
                                @"projectNameKeyword":@"",
                                @"sourcelangkey":sourceKey,
                                @"targetlangkey":targetKey,
                                @"vmId":@"0"};
    [AvailableNetWorking postWithUrl:projectManager_connector params:parameter successHandler:^(id responseObject) {
        
        self.projectBaseModel = [MJProjectBaseModel mj_objectWithKeyValues:responseObject];
        [self.projectList removeAllObjects];
        for (MJProjectListModel *model in self.projectBaseModel.result) {
            MJ_TaskCellLayout *layout = [[MJ_TaskCellLayout alloc] initWithModel:model];
            [self.projectList addObject:layout];
        }
        success(YES);
    } falureHandler:^(NSError *error) {
        success(NO);
    }];
}
//搜索项目（项目名称）
- (void)loadProjectWithProjectName:(NSString *)name success:(OperationResultBlock)success{
    NSDictionary *parameter = @{@"pagenum":@"1",
                                @"pagesize":@"500",
                                @"projectNameKeyword":name,
                                @"sourcelangkey":@"",
                                @"targetlangkey":@"",
                                @"vmId":@"0"};
    [AvailableNetWorking postWithUrl:projectManager_connector params:parameter successHandler:^(id responseObject) {
        self.projectBaseModel = [MJProjectBaseModel mj_objectWithKeyValues:responseObject];
        [self.searchProjectList removeAllObjects];
        for (MJProjectListModel *model in self.projectBaseModel.result) {
            MJ_TaskCellLayout *layout = [[MJ_TaskCellLayout alloc] initWithModel:model];
            [self.searchProjectList addObject:layout];
        }
        success(YES);
    } falureHandler:^(NSError *error) {
        success(NO);
    }];
}
//搜索项目（项目经理）
- (void)loadProjectWithProjectManager:(NSString *)manager success:(OperationResultBlock)success{
    NSDictionary *parameter = @{@"pagenum":@"1",
                                @"pagesize":@"500",
                                @"projectNameKeyword":@"",
                                @"sourcelangkey":@"",
                                @"targetlangkey":@"",
                                @"vmId":manager};
    [AvailableNetWorking postWithUrl:projectManager_connector params:parameter successHandler:^(id responseObject) {
        self.projectBaseModel = [MJProjectBaseModel mj_objectWithKeyValues:responseObject];
        [self.searchProjectList removeAllObjects];
        for (MJProjectListModel *model in self.projectBaseModel.result) {
            MJ_TaskCellLayout *layout = [[MJ_TaskCellLayout alloc] initWithModel:model];
            [self.searchProjectList addObject:layout];
        }
        success(YES);
    } falureHandler:^(NSError *error) {
        success(NO);
    }];
}


- (void)loadLanguagelistWithSuccess:(OperationResultBlock)success {
    [AvailableNetWorking getWithUrl:languageList_connector params:@{} successHandler:^(id responseObject) {
//        TGLog(@"%@",responseObject);
        MJ_LanguageBaseModel *baseModel = [MJ_LanguageBaseModel mj_objectWithKeyValues:responseObject];
        self.languagelist = baseModel.result;
        success(YES);
    } falureHandler:^(NSError *error) {
        success(NO);
    }];
    
}

@end
